package StudyCode.summary.mycollection;

import java.util.Iterator;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class IterableEqual {
	public static <T> boolean equal(Iterable<T> first, Iterable<T> second) {
		return equal(first.iterator(), second.iterator());
	}

	public static <T> boolean equal(Iterator<T> first, Iterator<T> second) {
		while (first.hasNext() && second.hasNext()) {
			T message = first.next();
			T otherMessage = second.next();
			if (!(message == null ? otherMessage == null : message
					.equals(otherMessage))) {
				return false;
			}
		}
		return !(first.hasNext() || second.hasNext());
	}
}
